package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HmsOrderCost;
import com.ruoyi.system.service.IHmsOrderCostService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单费用信息Controller
 * 
 * @author ruoyi
 * @date 2021-08-16
 */
@Controller
@RequestMapping("/system/cost")
public class HmsOrderCostController extends BaseController
{
    private String prefix = "system/cost";

    @Autowired
    private IHmsOrderCostService hmsOrderCostService;

    @RequiresPermissions("system:cost:view")
    @GetMapping()
    public String cost()
    {
        return prefix + "/cost";
    }

    /**
     * 查询订单费用信息列表
     */
    @RequiresPermissions("system:cost:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HmsOrderCost hmsOrderCost)
    {
        startPage();
        List<HmsOrderCost> list = hmsOrderCostService.selectHmsOrderCostList(hmsOrderCost);
        return getDataTable(list);
    }

    /**
     * 导出订单费用信息列表
     */
    @RequiresPermissions("system:cost:export")
    @Log(title = "订单费用信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HmsOrderCost hmsOrderCost)
    {
        List<HmsOrderCost> list = hmsOrderCostService.selectHmsOrderCostList(hmsOrderCost);
        ExcelUtil<HmsOrderCost> util = new ExcelUtil<HmsOrderCost>(HmsOrderCost.class);
        return util.exportExcel(list, "订单费用信息数据");
    }

    /**
     * 新增订单费用信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单费用信息
     */
    @RequiresPermissions("system:cost:add")
    @Log(title = "订单费用信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HmsOrderCost hmsOrderCost)
    {
        return toAjax(hmsOrderCostService.insertHmsOrderCost(hmsOrderCost));
    }

    /**
     * 修改订单费用信息
     */
    @GetMapping("/edit/{costId}")
    public String edit(@PathVariable("costId") Long costId, ModelMap mmap)
    {
        HmsOrderCost hmsOrderCost = hmsOrderCostService.selectHmsOrderCostByCostId(costId);
        mmap.put("hmsOrderCost", hmsOrderCost);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单费用信息
     */
    @RequiresPermissions("system:cost:edit")
    @Log(title = "订单费用信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HmsOrderCost hmsOrderCost)
    {
        return toAjax(hmsOrderCostService.updateHmsOrderCost(hmsOrderCost));
    }

    /**
     * 删除订单费用信息
     */
    @RequiresPermissions("system:cost:remove")
    @Log(title = "订单费用信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hmsOrderCostService.deleteHmsOrderCostByCostIds(ids));
    }
}
